//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Scene2D/Types/Transform2D.h"

namespace Engine
{
namespace Scene2D
{

	namespace ERenderLayer
	{
		enum type
		{
			SHADOW		= 0,
			BACKGROUND,
			OPAQUE_1,
			OPAQUE_2,
			OPAQUE_3,
			OPAQUE_4,
			OPAQUE_5,
			TRANSLUCENT,
			FOREGROUND,
			_COUNT
		};
		UX_ENUM_ADD_OPERATIONS( type );


		enum bits
		{
			SHADOW_BIT		= 1 << SHADOW,
			BACKGROUND_BIT	= 1 << BACKGROUND,
			OPAQUE_BITS		= (1 << OPAQUE_1) | (1 << OPAQUE_2) | (1 << OPAQUE_3) | (1 << OPAQUE_4) | (1 << OPAQUE_5),
			TRANSLUCENT_BIT	= 1 << TRANSLUCENT,
			FOREGROUND_BIT	= 1 << FOREGROUND,
			ALL_BITS		= (1 << _COUNT) - 1
		};
		UX_ENUM_BIT_OPERATIONS( bits );


		inline bits ToBit (type t)
		{
			return bits( 1 << t );
		}
	}



	//
	// Render Object
	//

	struct RenderObject
	{
	// types
	public:
		typedef void (* DrawProc_t) (const RenderObject &ro);


	// variables
	private:
		DrawProc_t		_drawProc;
		void *			_renderObj;
		void *			_param;
		Transform2D		_transform;
		float			_depth;


	// methods
	public:
		RenderObject () : _drawProc(null), _renderObj(null), _param(null), _depth(0.0f)
		{}

		void Create (DrawProc_t drawProc, void *renderObj, void *param)
		{
			_drawProc	= drawProc;
			_renderObj	= renderObj;
			_param		= param;
		}

		void Update (const Transform2D &tr, float depth)
		{
			_transform	= tr;
			_depth		= depth;
		}
		

		void Draw () const
		{
			ASSERT( _drawProc != null );
			_drawProc( *this );
		}


		template <typename T>
		T *					GetRenderObj () const	{ return (T *) _renderObj; }

		template <typename T>
		T *					GetParameter () const	{ return (T *) _param; }

		float				GetDepth ()		const	{ return _depth; }

		Transform2D const &	GetTransform ()	const	{ return _transform; }
	};


}	// Scene2D
}	// Engine